home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.awt;
-
- import java.awt.Event;
- import java.awt.Image;
-
- public class DbDataSource implements DataSource {
- Matrix rowCache = new Matrix();
- Grid view;
- DbDataStore store;
- DbDataUpdater updater;
- MetaTable meta;
- boolean caching = false;
- Data currData;
- int currDataRow;
- int currDataCol;
-
- public DbDataSource(DbDataStore s, DbDataUpdater u, MetaTable m) {
- this.setupSource(s, u, m);
- }
-
- public Grid getView() {
- return this.view;
- }
-
- public void setupSource(DbDataStore s, DbDataUpdater u, MetaTable m) {
- this.store = s;
- this.store.setDbDataSource(this);
- this.updater = u;
- this.meta = m;
- if (this.meta != null) {
- this.meta.setDbDataSource(this);
- }
-
- this.caching = !this.store.supportsCaching();
- }
-
- public void setGrid(Grid v) {
- this.view = v;
- }
-
- public void setDefaultData(Data defaultValue) {
- }
-
- public void setDefaultData() {
- }
-
- public boolean supportsMeta() {
- return this.meta != null;
- }
-
- public Matrix getCache() {
- return this.rowCache;
- }
-
- public int lastCachedRow() {
- return this.rowCache.rows() - 1;
- }
-
- public MetaTable getMetaTable() {
- return this.meta;
- }
-
- public void setupGrid(Grid v) throws TypeNotSupported {
- if (this.meta == null) {
- throw new TypeNotSupported("MetaTable not set");
- } else {
- this.meta.setupGrid(this.view);
- }
- }
-
- public void commitData() throws TypeNotSupported {
- if (this.currData != null && this.currData.changed()) {
- this.setData(this.currDataRow, this.currDataCol - 1, this.currData);
- this.currData.commit();
- this.currData = null;
- this.currDataRow = -1;
- }
-
- }
-
- public void setCurrentRow(int row) throws TypeNotSupported {
- this.store.setCurrentRow(row);
- }
-
- public Data readData(int row, int col) throws DataNotAvailable {
- ++col;
- if (this.currDataRow == row && this.currDataCol == col) {
- return this.currData;
- } else if (this.caching && this.rowCache.contains(row, col)) {
- return (Data)this.rowCache.elementAt(row, col);
- } else {
- Data d = this.store.getData(row, col);
- if (this.caching) {
- this.rowCache.addElement(row, col, d);
- this.markClean(row);
- }
-
- return d;
- }
- }
-
- public Data getData(Coordinate coords) throws DataNotAvailable {
- return this.getData(coords.row, coords.col);
- }
-
- public Data getData(int row, int col) throws DataNotAvailable {
- ++col;
- if (this.currDataRow == row && this.currDataCol == col) {
- return this.currData;
- } else {
- this.currData = this.readData(row, col - 1);
- this.currDataRow = row;
- this.currDataCol = col;
- return this.currData;
- }
- }
-
- public void addResultSetRow(int row, Data[] data) {
- for(int col = 1; col <= data.length; ++col) {
- this.rowCache.updateElement(row, col, data[col - 1]);
- }
-
- this.markClean(row);
- }
-
- public void setData(int row, int col, Data data) throws TypeNotSupported {
- ++col;
- if (this.caching) {
- this.rowCache.updateElement(row, col, data);
- this.markModified(row);
- } else {
- this.store.update(row, col, data);
- }
- }
-
- public void setData(Coordinate coord, Data data) throws TypeNotSupported {
- this.setData(coord.row, coord.col, data);
- }
-
- public String getText(Coordinate coords) throws DataNotAvailable {
- return this.getData(coords).toString();
- }
-
- public void undeleteRow(int row) throws TypeNotSupported {
- if (this.caching) {
- this.markModified(row);
- }
-
- this.updater.undeleteRow(row);
- }
-
- public void deleteRow(int row) throws TypeNotSupported {
- if (this.caching) {
- this.markDeleted(row);
- }
-
- this.updater.deleteRow(row);
- }
-
- public void insertRow(int row) throws TypeNotSupported {
- this.updater.insertRow(row);
- }
-
- public int appendRow() throws TypeNotSupported {
- return this.updater.appendRow();
- }
-
- public boolean supports(Coordinate coords, int type) {
- return type == 1;
- }
-
- public Image getImage(Coordinate coords) throws DataNotAvailable {
- return this.getData(coords).toImage();
- }
-
- public boolean handleEvent(Event e) {
- switch (e.id) {
- case 54:
- this.rollback();
- case 1005:
- default:
- return false;
- }
- }
-
- public void handleException(int row, int col, Exception ex) {
- this.view.handleException(row, col, ex);
- }
-
- public int rowState(int row) {
- return this.store.rowState(row);
- }
-
- public void clear() {
- this.rowCache.removeAllElements();
- this.store.clear();
- }
-
- public void refresh() {
- this.rowCache.removeAllElements();
- this.store.refresh();
- }
-
- public void undoRow(int row) throws TypeNotSupported {
- this.store.undoRow(row);
- }
-
- public void save() throws TypeNotSupported {
- this.updater.save();
- }
-
- public boolean isDataEditable(int row, int col) {
- if (this.meta != null) {
- try {
- return this.meta.isDataEditable(row, col + 1);
- } catch (DataNotAvailable var3) {
- return false;
- }
- } else {
- return true;
- }
- }
-
- protected void markModified(int row) {
- if (this.rowCache.contains(row, 0)) {
- RowState state = (RowState)this.rowCache.elementAt(row, 0);
- state.markModified();
- } else {
- RowState state = new RowState();
- this.rowCache.addElement(row, 0, state);
- state.markNew();
- }
- }
-
- protected void markNew(int row) {
- RowState state;
- if (this.rowCache.contains(row, 0)) {
- state = (RowState)this.rowCache.elementAt(row, 0);
- } else {
- state = new RowState();
- this.rowCache.addElement(row, 0, state);
- }
-
- state.markNew();
- }
-
- protected void markDeleted(int row) {
- RowState state = (RowState)this.rowCache.elementAt(row, 0);
- state.markDeleted();
- }
-
- protected void markClean(int row) {
- RowState state;
- if (this.rowCache.contains(row, 0)) {
- state = (RowState)this.rowCache.elementAt(row, 0);
- } else {
- state = new RowState();
- this.rowCache.addElement(row, 0, state);
- }
-
- state.markClean();
- }
-
- public int validDataRowRange(int top, int bottom) throws DataNotAvailable {
- return this.store.validDataRowRange(top, bottom) - 1;
- }
-
- public int rows() {
- return this.store.rowsRetrieved();
- }
-
- public int type(int row, int col) {
- return 1;
- }
-
- public void rollback(int row, int col) {
- this.rollback();
- }
-
- public void rollbackCurrentData() {
- this.rollback();
- }
-
- public void rollback() {
- this.currData = null;
- this.currDataRow = -1;
- }
-
- public void commit(int row, int col) {
- }
-
- public boolean isMasked(int row, int col) {
- return false;
- }
-
- public String getMask(int row, int col) throws TypeNotSupported {
- throw new TypeNotSupported("stubbed");
- }
-
- public boolean supportsChoice(int row, int col) {
- return false;
- }
-
- public Data[] getChoices(int row, int col) throws TypeNotSupported {
- throw new TypeNotSupported("stubbed");
- }
-
- public void setText(int row, int col, String t) {
- }
-
- public void insertChar(int row, int col, int pos, char c) {
- }
-
- public void setText(int row, int col, char c) {
- }
-
- public void appendChar(int row, int col, char c) {
- }
-
- public void clearText(int row, int col) {
- }
-
- public void deleteChar(int row, int col, int pos) {
- }
-
- public String subString(int row, int col, int spos, int epos) {
- return "stubbed";
- }
-
- public void setImage(int row, int col, Image i) {
- }
-
- public String toString(int row, int col) {
- return "stubbed";
- }
-
- public Image toImage(int row, int col) {
- return null;
- }
- }
-